var app = require('../app'),
    formMod = require('../../modules/form'),
    ajaxLock = true;

$("body")
    .on('blur',"#search_str",function(){
        var search_str = $("#search_str").val();
        $.ajax({
            url: '/entryrepay/searchCases',
            type: 'post',
            data: {
                'search_str':search_str
            },
            dataType: "json",
            success: function(res){
                if(res.code == 200){
                    var casesArr = res.data;
                    var casesStr = '<table class="table table-bordered table-striped table-hover" style="width:60%;margin-left:18%;"><thead><tr><th scope="col">序号</th><th scope="col">案件号</th><th scope="col">金融机构</th><th scope="col">当事人</th><th scope="col">管辖法院</th><th scope="col">操作</th></tr></thead><tbody>';
                    for(k=0;k<casesArr.length;k++){
                        casesStr +='<tr>';
                            if(k==0){
                                casesStr +='<td><input type="radio" name="case_id" checked value="'+ casesArr[k].id +'"></td>';
                            }else{
                                casesStr +='<td><input type="radio" name="case_id" value="'+ casesArr[k].id +'"></td>';
                            }
                        casesStr +=
                            '<td>'+ casesArr[k].id +'</td>' +
                            '<td>'+ casesArr[k].plaintiff_name +'</td>' +
                            '<td>'+ casesArr[k].defendant_name +'</td>' +
                            '<td>'+ casesArr[k].court +'</td>' +
                            '<td><a  target=“_blank” href="/caseInfo/caseInfo?case_id='+ casesArr[k].id +'">查看</a></td>' +
                            '</tr>';
                    }
                    casesStr += '</tbody></table>'
                    $('#casesArr').empty().append(casesStr);
                }else{
                    toastr.error(res.message);
                }
            },
            error: function(err){
                toastr.error('网络错误,请稍后重试');
            }
        })

    })
